package com.order.controller;

import com.order.iClient.IGoodsClient;
import com.order.resp.Item;
import com.order.resp.OrderResp;
import com.order.resp.RepsVo;
import com.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IGoodsClient goodsClient;

    /**
     * 创建订单
     */
    @RequestMapping("/create")
    public OrderResp createOrder(){

        System.out.println("------接收到创建订单请求----------");

        OrderResp orderResp = new OrderResp();

        orderResp.setCode("0");
        orderResp.setMsg("创建订单成功");

        orderResp.setOrderDetail(orderService.createOrder());

        return orderResp;
    }


    /**
     * 创建订单
     */
    @RequestMapping("/create1")
    public OrderResp createOrder1(){

        //验证token

        OrderResp orderResp = new OrderResp();

        orderResp.setCode("0");
        orderResp.setMsg("创建订单成功");

        orderResp.setOrderDetail(orderService.createOrder1());

        return orderResp;
    }

    @RequestMapping("/test")
    public RepsVo feginTest(){

        System.out.println("----------feigin调用---" );


        RepsVo<Item> repsVo = goodsClient.queryByGoodsId("1001");

        System.out.println("----------repsVo---" + repsVo);


        return repsVo;
    }

    @RequestMapping("/update")
    public String update(){
        System.out.println("---------忽略---");
        return "this is update";
    }


}
